//
//  ACEDrawingView+List.m
//  NaRiLSVMT
//
//  Created by zhangmeng on 14-9-4.
//  Copyright (c) 2014年 helloyouth.org. All rights reserved.
//

#import "ACEDrawingView+List.h"
#import "TcpClient.h"

@implementation ACEDrawingView (List)
- (void)installDropDownListView
{
    if (!self.dropListView) {
        self.dropListView = [[DropDownListView alloc] initWithFrame:CGRectMake(0,0,100,0) dataSource:self delegate:self Tag:@"0"];
        self.dropListView.mSuperView = self;
        self.dropListView.screenHeight = self.screenHeight;
        self.dropListView.screenWidth = self.screenWidth;
        self.dropListView.forScreenFlag = self.forScreenFlag;
        self.dropListView.doubleClickflag = self.doubleClickflag;
        self.dropListView.natureNum = 0;
        if(![self.subviews containsObject:self.dropListView]){
            [self addSubview:self.dropListView];
        }
        self.dicData = [NSMutableDictionary dictionary];
        [AddNoticeObserver(NoticeKey_TcpGetEvents){
            //后台数据转换
            self.jsonGetevents = [note object];
            NSDictionary *dic1 = [Common jsontoArray:self.jsonGetevents];
            NSDictionary *dic2 =  dic1[@"messageData"];
            NSArray *dic3 = dic2[@"message"];
            NSDictionary *dic4 = dic3[0];
            NSDictionary *dic5 = dic4[@"Result"];
            self.btnDataArr = [NSMutableArray arrayWithArray:dic5[@"Items"]];
            [self drawButtonTalk];
            NSLog(@"dsfds");
        }];
    }
}
-(void)chooseAtSection:(NSInteger)section index:(NSInteger)index
{
    //点击事件的处理  发送tcp命令
//    if(self.forScreenFlag || self.forScreenall){
        self.colseEvent = YES;
        NSArray *tmparr = [NSArray arrayWithArray:self.btnDataArr[section][@"Events"]];
        NSString *vlaue = StringFromId(self.btnDataArr[section][@"Guid"]);
        NSString *tmpstr = StringFromId(tmparr[index]);
        NSString *strr = [tmpstr substringToIndex:tmpstr.length-2];
        NSString *events = [strr substringFromIndex:6];
        // NSString *events = StringFromId(tmparr[index]);
        TcpClient *tcp = [TcpClient sharedInstance];
        dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
           // for(NSString *host in self.hostIdarr){
            [tcp writeString:[Common performEventstring:[self.hostIdarr[0] intValue] Metuod:@"ExcuteEvent" Value:vlaue Events:events]];
           // }
        });
//    }
//    else{
//        
//    }
}
-(NSInteger)numberOfSections
{
    return 1;
}
-(NSInteger)numberOfRowsInSection:(NSInteger)section
{
    NSArray *tmparr = [NSArray arrayWithArray:self.btnDataArr[section][@"Events"]];
    if([tmparr count]){
        return [tmparr count];
    }
    else{
        return 0;
    }
}
-(NSString *)titleInSection:(NSInteger)section index:(NSInteger) index
{
    NSArray *tmparr = [NSArray arrayWithArray:self.btnDataArr[section][@"Events"]];
    NSString *tmpstr = StringFromId(tmparr[index]);
    NSString *strr = [tmpstr substringToIndex:tmpstr.length-2];
    NSString *strpp = [strr substringFromIndex:5];
    return strpp;
}
-(NSInteger)defaultShowSection:(NSInteger)section
{
    return 0;
}
-(void)moveViewBtn:(NSInteger)section
{
    
}

@end
